#include "LogicList.h"

LogicList& LogicList::getInstance() {

	if (_logicList == NULL) {
		_logicList = new LogicList;
	}

	return *_logicList;
}

LogicList::LogicList() {

}

Display LogicList::listAllTasks() {
	
	string statusMessage;
	Data::DataFeedback dataFeedback;
	vector<Task> tasks;

	dataFeedback = _data->getAll(tasks);

	if( dataFeedback == Data::NOT_FOUND ) {
		throw(NOT_FOUND_ERROR_MESSAGE);
	}

	if( dataFeedback == Data::FAILURE ) {
		// log errors
	}

	if( dataFeedback == Data::SUCCESS ) {
		statusMessage = LIST_SUCCESS_MESSAGE;
	} else {
		statusMessage = LIST_ERROR_MESSAGE;
	}

	_display = Display( statusMessage, tasks );
	return _display;
}

Display LogicList::listTaskBySearchTerm( string searchTerm ) {
	
	string statusMessage;
	Data::DataFeedback dataFeedback;
	vector<Task> tasks;

	dataFeedback = _data->getBySearchTerm(tasks, searchTerm);

	if( dataFeedback == Data::NOT_FOUND ) {
		throw(NOT_FOUND_ERROR_MESSAGE);
	}

	if( dataFeedback == Data::FAILURE ) {
		// log errors
	}

	if( dataFeedback == Data::SUCCESS ) {
		statusMessage = LIST_SUCCESS_MESSAGE;
	} else {
		statusMessage = LIST_ERROR_MESSAGE;
	}

	_display = Display( statusMessage, tasks );

	return _display;
}

Display LogicList::listTaskByDay( ptime day ) {

	string statusMessage;
	Data::DataFeedback dataFeedback;
	vector<Task> tasks;

	dataFeedback = _data->getByTime(tasks, day);

	if( dataFeedback == Data::NOT_FOUND ) {
		throw(NOT_FOUND_ERROR_MESSAGE);
	}

	if( dataFeedback == Data::FAILURE ) {
		// log errors
	}

	if( dataFeedback == Data::SUCCESS ) {
		statusMessage = LIST_SUCCESS_MESSAGE;
	} else {
		statusMessage = LIST_ERROR_MESSAGE;
	}

	_display = Display( statusMessage, tasks );

	return _display;
}

Display LogicList::listTaskByDate( ptime date ) {
	
	string statusMessage;
	Data::DataFeedback dataFeedback;
	vector<Task> tasks;

	dataFeedback = _data->getByTime(tasks, date);

	if( dataFeedback == Data::NOT_FOUND ) {
		throw(NOT_FOUND_ERROR_MESSAGE);
	}

	if( dataFeedback == Data::FAILURE ) {
		// log errors
	}

	if( dataFeedback == Data::SUCCESS ) {
		statusMessage = LIST_SUCCESS_MESSAGE;
	} else {
		statusMessage = LIST_ERROR_MESSAGE;
	}

	_display = Display( statusMessage, tasks );

	return _display;
}

Display LogicList::listTaskNextWeek( ptime week ) {

	string statusMessage;
	Data::DataFeedback dataFeedback;
	vector<Task> tasks;
	
	dataFeedback = _data->getByTime(tasks, week);

	if( dataFeedback == Data::NOT_FOUND ) {
		throw(NOT_FOUND_ERROR_MESSAGE);
	}

	if( dataFeedback == Data::FAILURE ) {
		// log errors
	}

	if( dataFeedback == Data::SUCCESS ) {
		statusMessage = LIST_SUCCESS_MESSAGE;
	} else {
		statusMessage = LIST_ERROR_MESSAGE;
	}

	_display = Display( statusMessage, tasks );

	return _display;
}

Display LogicList::listTaskByMonth( ptime month ) {

	string statusMessage;
	Data::DataFeedback dataFeedback;
	vector<Task> tasks;

	dataFeedback = _data->getByTime(tasks, month);

	if( dataFeedback == Data::NOT_FOUND ) {
		throw(NOT_FOUND_ERROR_MESSAGE);
	}

	if( dataFeedback == Data::FAILURE ) {
		// log errors
	}

	if( dataFeedback == Data::SUCCESS ) {
		statusMessage = LIST_SUCCESS_MESSAGE;
	} else {
		statusMessage = LIST_ERROR_MESSAGE;
	}

	_display = Display( statusMessage, tasks );

	return _display;
}

Display LogicList::listTaskByDone( bool done ) {

	string statusMessage;
	Data::DataFeedback dataFeedback;
	vector<Task> tasks;

	dataFeedback = _data->getByDone(tasks);

	if( dataFeedback == Data::NOT_FOUND ) {
		throw(NOT_FOUND_ERROR_MESSAGE);
	}

	if( dataFeedback == Data::FAILURE ) {
		// log errors
	}

	if( dataFeedback == Data::SUCCESS ) {
		statusMessage = LIST_SUCCESS_MESSAGE;
	} else {
		statusMessage = LIST_ERROR_MESSAGE;
	}

	_display = Display( statusMessage, tasks );

	return _display;
}

const string LogicList::LIST_SUCCESS_MESSAGE = "List Completed";
const string LogicList::LIST_ERROR_MESSAGE = "Unable To List";
LogicList* LogicList::_logicList = NULL;